using System;

namespace Lazy.Captcha.Core.RateLimit
{
    /// <summary>
    /// 频率限制超出异常
    /// </summary>
    public class RateLimitExceededException : Exception
    {
        /// <summary>
        /// 剩余请求次数
        /// </summary>
        public int RemainingRequests { get; }

        /// <summary>
        /// 下次重置时间
        /// </summary>
        public DateTime? ResetTime { get; }

        /// <summary>
        /// 时间窗口（秒）
        /// </summary>
        public int WindowSeconds { get; }

        /// <summary>
        /// 最大请求次数
        /// </summary>
        public int MaxRequests { get; }

        public RateLimitExceededException(int remainingRequests, DateTime? resetTime, int windowSeconds, int maxRequests)
            : base($"频率限制超出：{windowSeconds}秒内最多允许{maxRequests}次请求，剩余{remainingRequests}次")
        {
            RemainingRequests = remainingRequests;
            ResetTime = resetTime;
            WindowSeconds = windowSeconds;
            MaxRequests = maxRequests;
        }

        public RateLimitExceededException(string message, int remainingRequests, DateTime? resetTime, int windowSeconds, int maxRequests)
            : base(message)
        {
            RemainingRequests = remainingRequests;
            ResetTime = resetTime;
            WindowSeconds = windowSeconds;
            MaxRequests = maxRequests;
        }
    }
}
